
from Model import *
from NotificationsUtils import *

__author__ = 'Oryan'

class MyHistoryRacesHandler(webapp2.RequestHandler):
    def get(self):
        user = ndb.Key('User', int(self.request.get("user")))
        historyRaces = RaceHistory.query(RaceHistory.Racer == user)
        racesToJson = [{"Key": historyRace.key.id(), "Grade": historyRace.Grade, "TotalDistance" : historyRace.Distance,\
                        "Distance":historyRace.ActualDistance,"Time": str(historyRace.FinishedTime),\
                        "IsFinished": historyRace.IsFinished, "Position": historyRace.Position, "Date":str(historyRace.RaceDate),\
                        "averageSpeed" : historyRace.AverageSpeed} for historyRace in historyRaces]

        self.response.content_type = 'application/json'
        self.response.out.write(json.dumps(racesToJson))

